<?php

namespace app\models\jasper;

trait JasperApiTerminalTrait
{
    /**
     * 为给定设备更改单个属性的值。您可以指定该更改立即生效，或计划在将来的某个日期生效。
     * @param string $iccid ICCID
     * @param integer $changeType
     * 3 - SIM Status:
     * "TEST_READY_NAME": Test Ready,
     * "INVENTORY_NAME": Inventory,
     * "TRIAL_NAME": Trial,
     * "ACTIVATION_READY_NAME": Activation Ready,
     * "ACTIVATED_NAME": Activated,
     * "DEACTIVATED_NAME": Deactivated,
     * "RETIRED_NAME": Retired,
     * "PURGED_NAME": Purged
     * @param string $targetValue
     * @param integer $effectiveDate
     * @return \stdClass
     * @throws \Exception
     */
    public function EditTerminal($iccid, $changeType = 0, $targetValue = '', $effectiveDate = 0)
    {
        $json = [
            'iccid' => $iccid,
            'changeType' => $changeType,
            'targetValue' => $targetValue,
        ];
        if ($effectiveDate > 0) {
            $json['effectiveDate'] = date('c', $effectiveDate);
            $json['effectiveDateSpecified'] = true;
        }
        return $this->call(
            preg_replace('/.*JasperApi(.*?)Trait/', '$1', __TRAIT__),
            __FUNCTION__,
            $json
        );
    }

    /**
     * @param string $iccid
     * @param integer $termStartDate
     * @param boolean $termStartDateSpecified
     * @param integer $termEndDate
     * @param boolean $termEndDateSpecified
     * @param string $renewalMode
     * @param string $renewalRatePlan
     * @return \stdClass
     * @throws \Exception
     */
    public function EditTerminalRating($iccid, $termStartDate = 0, $termStartDateSpecified = false, $termEndDate = 0, $termEndDateSpecified = false, $renewalMode = '', $renewalRatePlan = '')
    {
        return $this->call(
            preg_replace('/.*JasperApi(.*?)Trait/', '$1', __TRAIT__),
            __FUNCTION__,
            [
                'iccid' => $iccid,
                'termStartDate' => date('c', $termStartDate),
                'termStartDateSpecified' => $termStartDateSpecified,
                'termEndDate' => date('c', $termEndDate),
                'termEndDateSpecified' => $termEndDateSpecified,
                'renewalMode' => $renewalMode,
                'renewalRatePlan' => $renewalRatePlan,
            ]
        );
    }

    /**
     * 返回关于列表中每个设备的详细信息。
     * 注意如果只传入一条，返回值中：terminals->terminal是对象，否则是数组。
     * @param string[] $iccids ICCID列表
     * @return \stdClass
     * @throws \Exception
     */
    public function GetTerminalDetails($iccids)
    {
        return $this->call(
            preg_replace('/.*JasperApi(.*?)Trait/', '$1', __TRAIT__),
            __FUNCTION__,
            [
                'iccids' => $iccids,
            ]
        );
    }

    /**
     * @param string $operatorAccountId
     * @return \stdClass
     * @throws \Exception
     */
    public function GetLinePayStatusByOpAcctId($operatorAccountId)
    {
        return $this->call(
            preg_replace('/.*JasperApi(.*?)Trait/', '$1', __TRAIT__),
            __FUNCTION__,
            [
                'operatorAccountId' => $operatorAccountId,
            ]
        );
    }

    /**
     * @param string $iccid
     * @param string $linePaymentStatus
     * @return \stdClass
     * @throws \Exception
     */
    public function EditLinePayStatus($iccid, $linePaymentStatus)
    {
        return $this->call(
            preg_replace('/.*JasperApi(.*?)Trait/', '$1', __TRAIT__),
            __FUNCTION__,
            [
                'iccid' => $iccid,
                'linePaymentStatus' => $linePaymentStatus,
            ]
        );
    }

    /**
     * @param string $operatorAccountId
     * @param string $linePaymentStatus
     * @return \stdClass
     * @throws \Exception
     */
    public function EditLinePayStatusPerAcct($operatorAccountId, $linePaymentStatus)
    {
        return $this->call(
            preg_replace('/.*JasperApi(.*?)Trait/', '$1', __TRAIT__),
            __FUNCTION__,
            [
                'operatorAccountId' => $operatorAccountId,
                'linePaymentStatus' => $linePaymentStatus,
            ]
        );
    }

    /**
     * @param string $iccid
     * @param string $msisdn
     * @param integer $accountid
     * @param string $ratePlan
     * @param string $communicationPlan
     * @param integer $dateShipped
     * @param boolean $dateShippedSpecified
     * @return \stdClass
     * @throws \Exception
     */
    public function TransferTerminalAccountNoSimStatus($iccid, $msisdn, $accountid = 0, $ratePlan = '', $communicationPlan = '', $dateShipped = 0, $dateShippedSpecified = false)
    {
        return $this->call(
            preg_replace('/.*JasperApi(.*?)Trait/', '$1', __TRAIT__),
            __FUNCTION__,
            [
                'iccid' => $iccid,
                'msisdn' => $msisdn,
                'accountid' => $accountid,
                'ratePlan' => $ratePlan,
                'communicationPlan' => $communicationPlan,
                'dateShipped' => date('c', $dateShipped),
                'dateShippedSpecified' => $dateShippedSpecified,
            ]
        );
    }

    /**
     * @param string $iccid
     * @return \stdClass
     * @throws \Exception
     */
    public function GetTerminalRating($iccid)
    {
        return $this->call(
            preg_replace('/.*JasperApi(.*?)Trait/', '$1', __TRAIT__),
            __FUNCTION__,
            [
                'iccid' => $iccid,
            ]
        );
    }

    /**
     * @param string $iccid
     * @param string $renewalRatePlan
     * @return \stdClass
     * @throws \Exception
     */
    public function QueueTerminalRatePlan($iccid, $renewalRatePlan)
    {
        return $this->call(
            preg_replace('/.*JasperApi(.*?)Trait/', '$1', __TRAIT__),
            __FUNCTION__,
            [
                'iccid' => $iccid,
                'renewalRatePlan' => $renewalRatePlan,
            ]
        );
    }

    /**
     * @param string $iccid
     * @param integer $queuePosition
     * @param string $ratePlan
     * @return \stdClass
     * @throws \Exception
     */
    public function RemoveRatePlanFromQueue($iccid, $queuePosition = 0, $ratePlan = '')
    {
        return $this->call(
            preg_replace('/.*JasperApi(.*?)Trait/', '$1', __TRAIT__),
            __FUNCTION__,
            [
                'iccid' => $iccid,
                'queuePosition' => $queuePosition,
                'ratePlan' => $ratePlan,
            ]
        );
    }

    /**
     * 返回自给定日期和时间以后已发生修改的所有设备的 ICCID 列表。要获得所有设备的列表，只需忽略“since”参数。
     * @param integer $since
     * @param string $simState
     * @param integer $pageNumber
     * @param integer $accountId
     * @return \stdClass
     * @throws \Exception
     */
    public function GetModifiedTerminals($since = 0, $simState = null, $pageNumber = 0, $accountId = 0)
    {
        $json = [];
        if (!empty($since)) {
            $json['since'] = date('c', $since);
            $json['sinceSpecified'] = true;
        }
        if (!empty($simState)) {
            $json['simState'] = $simState;
            $json['simStateSpecified'] = true;
        }
        if (!empty($pageNumber)) {
            $json['pageNumber'] = $pageNumber;
            $json['pageNumberSpecified'] = true;
        }
        if (!empty($accountId)) {
            $json['accountId'] = $accountId;
            $json['accountIdSpecified'] = true;
        }
        return $this->call(
            preg_replace('/.*JasperApi(.*?)Trait/', '$1', __TRAIT__),
            __FUNCTION__,
            $json
        );
    }

    /**
     * 返回与给定的 Secure SIM ID 对应的设备列表。
     * @param string $secureSimId
     * @return \stdClass
     * @throws \Exception
     */
    public function GetTerminalsBySecureSimId($secureSimId)
    {
        return $this->call(
            preg_replace('/.*JasperApi(.*?)Trait/', '$1', __TRAIT__),
            __FUNCTION__,
            [
                'secureSimId' => $secureSimId,
            ]
        );
    }

    /**
     * 返回一个或多个设备的当前会话信息(IP 地址和会话开始时间)。如果指定的设备不在线，则不返回信息。
     * @param string[] $iccid
     * @return \stdClass
     * @throws \Exception
     */
    public function GetSessionInfo($iccid = [])
    {
        return $this->call(
            preg_replace('/.*JasperApi(.*?)Trait/', '$1', __TRAIT__),
            __FUNCTION__,
            [
                'iccid' => $iccid,
            ]
        );
    }

    /**
     * 返回与给定的一组设备电话号码 (MSISDN) 对应的 ICCID 列表。
     * @param string[] $msisdns
     * @return \stdClass
     * @throws \Exception
     */
    public function GetTerminalsByMsisdn($msisdns = [])
    {
        return $this->call(
            preg_replace('/.*JasperApi(.*?)Trait/', '$1', __TRAIT__),
            __FUNCTION__,
            [
                'msisns' => $msisdns,
            ]
        );
    }

    /**
     * 返回与给定的一组设备 IMSI 对应的 ICCID 列表。
     * @param string[] $imsi
     * @return \stdClass
     * @throws \Exception
     */
    public function GetTerminalsByImsi($imsi = [])
    {
        return $this->call(
            preg_replace('/.*JasperApi(.*?)Trait/', '$1', __TRAIT__),
            __FUNCTION__,
            [
                'imsi' => $imsi,
            ]
        );
    }

    /**
     * @param string $iccid
     * @param string $exchangeSimIccid
     * @param string $externalRmaId
     * @return \stdClass
     * @throws \Exception
     */
    public function SimRmaExchange($iccid, $exchangeSimIccid, $externalRmaId)
    {
        return $this->call(
            preg_replace('/.*JasperApi(.*?)Trait/', '$1', __TRAIT__),
            __FUNCTION__,
            [
                'iccid' => $iccid,
                'exchangeSimIccid' => $exchangeSimIccid,
                'externalRmaId' => $externalRmaId,
            ]
        );
    }

    /**
     * @param string[] $iccids
     * @param string $username
     * @param string $password
     * @return \stdClass
     * @throws \Exception
     */
    public function UpdateSecureSimCredentials($iccids, $username, $password)
    {
        return $this->call(
            preg_replace('/.*JasperApi(.*?)Trait/', '$1', __TRAIT__),
            __FUNCTION__,
            [
                'iccids' => $iccids,
                'username' => $username,
                'password' => $password,
            ]
        );
    }

    /**
     * @param string[] $iccidList
     * @param integer $accountId
     * @param string $ratePlanName
     * @param string $commPlanName
     * @param string $callbackUrl
     * @return \stdClass
     * @throws \Exception
     */
    public function TransferSimsToAccount($iccidList, $accountId, $ratePlanName, $commPlanName, $callbackUrl)
    {
        return $this->call(
            preg_replace('/.*JasperApi(.*?)Trait/', '$1', __TRAIT__),
            __FUNCTION__,
            [
                'iccidList' => $iccidList,
                'accountId' => $accountId,
                'ratePlanName' => $ratePlanName,
                'commPlanName' => $commPlanName,
                'callbackUrl' => $callbackUrl,
            ]
        );
    }

    /**
     * @param string[] $iccidList
     * @param integer $accountId
     * @return \stdClass
     * @throws \Exception
     */
    public function TransferTrialSimsToAccount($iccidList, $accountId)
    {
        return $this->call(
            preg_replace('/.*JasperApi(.*?)Trait/', '$1', __TRAIT__),
            __FUNCTION__,
            [
                'iccidList' => $iccidList,
                'accountId' => $accountId,
            ]
        );
    }

    /**
     * 更改给定设备 IP 地址的值。
     * 此功能允许您自行管理 IP 地址，
     * 无需依赖运营商。
     * 您可以分配任何 IP 地址，
     * 只要该地址在给定范围内。
     * 特别是，与某个 IP 地址关联的设备已不再使用时，
     * 可以重复使用该地址。
     * @param string $iccid ICCID
     * @param string $apn
     * @param string $ipAddress IP地址
     * @param string $pdpId
     * @return \stdClass
     * @throws \Exception
     */
    public function AssignOrUpdateIPAddress($iccid, $apn, $ipAddress, $pdpId)
    {
        return $this->call(
            preg_replace('/.*JasperApi(.*?)Trait/', '$1', __TRAIT__),
            __FUNCTION__,
            [
                'iccid' => $iccid,
                'apn' => $apn,
                'ipAddress' => $ipAddress,
                'pdpId' => $pdpId,
            ]
        );
    }

    /**
     * 返回给定设备最新 SS7 网络注册的相关信息，包括注册运营商的名称以及网络节点的全球冠名地址。
     * 对于支持 LTE 的设备，您必须改用 GetTerminalLatestNetworkRegistration。
     * 此类信息可以帮助您识别设备上一次成功接入网络的时间和地点，从而对网络问题进行故障诊断。
     * 请注意，您的网络安装可能会影响此 API 的行为。如有任何疑问，请与您的运营商联系。
     * @param string $imsi
     * @return \stdClass
     * @throws \Exception
     */
    public function GetTerminalLatestRegistration($imsi)
    {
        return $this->call(
            preg_replace('/.*JasperApi(.*?)Trait/', '$1', __TRAIT__),
            __FUNCTION__,
            [
                'imsi' => $imsi,
            ]
        );
    }

    /**
     * 返回与 GetTerminalLatestRegistration 相同的信息，但适用于 SS7 和 Diameter 两种事件。该 API 适用于支持 2G/3G 和 LTE 的设备。
     * @param string $imsi
     * @return \stdClass
     * @throws \Exception
     */
    public function GetTerminalLatestNetworkRegistration($imsi)
    {
        return $this->call(
            preg_replace('/.*JasperApi(.*?)Trait/', '$1', __TRAIT__),
            __FUNCTION__,
            [
                'imsi' => $imsi,
            ]
        );
    }

    /**
     * @param string $iccid
     * @param integer $daysOfHistory
     * @param boolean $daysOfHistorySpecified
     * @param integer $date
     * @param boolean $dateSpecified
     * @param integer $pageNumber
     * @param boolean $pageNumberSpecified
     * @return \stdClass
     * @throws \Exception
     */
    public function GetTerminalAuditTrail($iccid, $daysOfHistory = 0, $daysOfHistorySpecified = false, $date = 0, $dateSpecified = false, $pageNumber = 0, $pageNumberSpecified = false)
    {
        return $this->call(
            preg_replace('/.*JasperApi(.*?)Trait/', '$1', __TRAIT__),
            __FUNCTION__,
            [
                'iccid' => $iccid,
                'daysOfHistory' => $daysOfHistory,
                'daysOfHistorySpecified' => $daysOfHistorySpecified,
                'date' => date('c', $date),
                'dateSpecified' => $dateSpecified,
                'pageNumber' => $pageNumber,
                'pageNumberSpecified' => $pageNumberSpecified,
            ]
        );
    }

    /**
     * 强制设备断开网络，使其重新注册。常用于纠正网络注册问题，此功能目前在 Control Center 中通过 Spotlight 提供。
     * @param string $iccid
     * @return \stdClass
     * @throws \Exception
     */
    public function SendCancelLocation($iccid)
    {
        return $this->call(
            preg_replace('/.*JasperApi(.*?)Trait/', '$1', __TRAIT__),
            __FUNCTION__,
            [
                'iccid' => $iccid,
            ]
        );
    }

    /**
     * @param string $iccid
     * @param integer $changeType
     * @param integer $accountId
     * @param boolean $accountIdSpecified
     * @return \stdClass
     * @throws \Exception
     */
    public function GetProvisioningStatus($iccid, $changeType = 0, $accountId = 0, $accountIdSpecified = false)
    {
        return $this->call(
            preg_replace('/.*JasperApi(.*?)Trait/', '$1', __TRAIT__),
            __FUNCTION__,
            [
                'iccid' => $iccid,
                'changeType' => $changeType,
                'accountId' => $accountId,
                'accountIdSpecified' => $accountIdSpecified,
            ]
        );
    }
}
